{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2bccf280-9f87-42ee-be24-89bfee067994",
   "metadata": {},
   "source": [
    "# Python代码规范\n",
    "\n",
    "Python的代码规范是指PEP 8（Python Enhancement Proposal 8），它是Python社区广泛接受的代码风格指南。\n",
    "\n",
    "1. **缩进：** 在Python中，缩进是非常重要的，它用于表示代码块。通常使用四个空格来进行缩进。\n",
    "\n",
    "    ```python\n",
    "    # 正确的缩进示例\n",
    "    if x > 5:\n",
    "        print(\"x is greater than 5\")\n",
    "    ```\n",
    "\n",
    "2. **行长度：** 每行代码的长度应该尽量控制在79个字符以内，超过的部分可以使用换行符进行换行。\n",
    "\n",
    "    ```python\n",
    "    # 行长度超过79个字符的换行示例\n",
    "    my_long_variable = (\n",
    "        \"This is a long string that exceeds the recommended line length, \"\n",
    "        \"so we use parentheses to break it into multiple lines.\"\n",
    "    )\n",
    "    ```\n",
    "\n",
    "3. **空行：** 在不同的代码块之间或函数定义之前应该留有空行，以提高可读性。\n",
    "\n",
    "    ```python\n",
    "    # 空行示例\n",
    "    def function1():\n",
    "        # Some code here\n",
    "        pass\n",
    "\n",
    "    # 空行分隔不同功能模块\n",
    "    def function2():\n",
    "        # Some code here\n",
    "        pass\n",
    "    ```\n",
    "\n",
    "4. **注释：** 良好的注释能够提高代码的可读性，注释应该清晰、简洁，并且符合PEP 257的文档字符串规范。\n",
    "\n",
    "    ```python\n",
    "    # 单行注释示例\n",
    "    x = 5  # Assign 5 to variable x\n",
    "\n",
    "    # 多行注释示例\n",
    "    \"\"\"\n",
    "    This is a multi-line comment or docstring.\n",
    "    It can be used for documenting modules, functions, classes, etc.\n",
    "    \"\"\"\n",
    "\n",
    "    def my_function():\n",
    "        \"\"\"\n",
    "        This function does something useful.\n",
    "        \"\"\"\n",
    "        pass\n",
    "    ```\n",
    "\n",
    "5. **命名规范：** 变量、函数、方法、模块等的命名应该清晰、简洁，并且符合下列命名规范：\n",
    "   - 变量和函数名应该使用小写字母，单词之间可以用下划线 `_` 分隔。\n",
    "   - 类名应该使用驼峰命名法，即每个单词的首字母大写，不使用下划线分隔。\n",
    "   - 模块名应该使用小写字母，可以使用下划线 `_` 分隔。\n",
    "\n",
    "    ```python\n",
    "    # 变量和函数命名示例\n",
    "    my_variable = 10\n",
    "    def my_function():\n",
    "        pass\n",
    "\n",
    "    # 类命名示例\n",
    "    class MyClass:\n",
    "        pass\n",
    "\n",
    "    # 模块命名示例\n",
    "    import my_module\n",
    "    ```\n",
    "\n",
    "6. **导入规范：** 尽可能在代码的顶部，使用单独的导入语句导入模块，避免使用 `import *`。\n",
    "\n",
    "    ```python\n",
    "    # 导入规范示例\n",
    "    import math\n",
    "    import sys\n",
    "    from os import path\n",
    "    ```\n",
    "\n",
    "遵循这些规范可以让你的代码更易读、易维护，并且与其他Python开发者共享代码时更为一致。\n",
    "an 5\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c5bf9d2-837e-4d16-8979-cd3423c08857",
   "metadata": {},
   "source": [
    "# Python关键字\n",
    "\n",
    "## 1. 关键字的概念\n",
    "\n",
    "关键字又称保留字，它是Python语言预先定义好的具有特定含义的标识符，用于记录特殊值或标识程序结构。\n",
    "\n",
    "## 2. Python 3.10的关键字\n",
    "\n",
    "Python 3.10版本的关键字包括以下内容：\n",
    "\n",
    "- False\n",
    "- None\n",
    "- True\n",
    "- and\n",
    "- as\n",
    "- assert\n",
    "- async\n",
    "- await\n",
    "- break\n",
    "- class\n",
    "- continue\n",
    "- def\n",
    "- del\n",
    "- elif\n",
    "- else\n",
    "- except\n",
    "- finally\n",
    "- for\n",
    "- from\n",
    "- global\n",
    "- if\n",
    "- import\n",
    "- in\n",
    "- is\n",
    "- lambda\n",
    "- nonlocal\n",
    "- not\n",
    "- or\n",
    "- pass\n",
    "- raise\n",
    "- return\n",
    "- try\n",
    "- while\n",
    "- with\n",
    "- yield\n",
    "\n",
    "## 3. 查看关键字的说明和使用方法的方式\n",
    "\n",
    "在命令提示符中进入Python环境，使用help()函数可查看每个关键字的说明以及使用方法。\n",
    "\n",
    "## 4. 通过命令提示符演示如何查看关键字\n",
    "\n",
    "你可以通过以下步骤在命令提示符中查看关键字的说明：\n",
    "\n",
    "1. 打开命令提示符或终端。\n",
    "2. 输入 `python` 进入Python交互式环境。\n",
    "3. 使用 `help()` 函数查看关键字的帮助文档，例如 `help('if')`。\n",
    "\n",
    "这样就可以查看特定关键字的说明和使用方法了。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "47644660-0fd1-4f9d-969b-4fcef2520940",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The \"if\" statement\n",
      "******************\n",
      "\n",
      "The \"if\" statement is used for conditional execution:\n",
      "\n",
      "   if_stmt ::= \"if\" assignment_expression \":\" suite\n",
      "               (\"elif\" assignment_expression \":\" suite)*\n",
      "               [\"else\" \":\" suite]\n",
      "\n",
      "It selects exactly one of the suites by evaluating the expressions one\n",
      "by one until one is found to be true (see section Boolean operations\n",
      "for the definition of true and false); then that suite is executed\n",
      "(and no other part of the \"if\" statement is executed or evaluated).\n",
      "If all expressions are false, the suite of the \"else\" clause, if\n",
      "present, is executed.\n",
      "\n",
      "Related help topics: TRUTHVALUE\n"
     ]
    }
   ],
   "source": [
    "help('if')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b933ae82-2ad1-4ff5-a325-f16a2588cd20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Welcome to Python 3.10's help utility!\n",
      "\n",
      "If this is your first time using Python, you should definitely check out\n",
      "the tutorial on the internet at https://docs.python.org/3.10/tutorial/.\n",
      "\n",
      "Enter the name of any module, keyword, or topic to get help on writing\n",
      "Python programs and using Python modules.  To quit this help utility and\n",
      "return to the interpreter, just type \"quit\".\n",
      "\n",
      "To get a list of available modules, keywords, symbols, or topics, type\n",
      "\"modules\", \"keywords\", \"symbols\", or \"topics\".  Each module also comes\n",
      "with a one-line summary of what it does; to list the modules whose name\n",
      "or summary contain a given string such as \"spam\", type \"modules spam\".\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "help>  'for'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The \"for\" statement\n",
      "*******************\n",
      "\n",
      "The \"for\" statement is used to iterate over the elements of a sequence\n",
      "(such as a string, tuple or list) or other iterable object:\n",
      "\n",
      "   for_stmt ::= \"for\" target_list \"in\" expression_list \":\" suite\n",
      "                [\"else\" \":\" suite]\n",
      "\n",
      "The expression list is evaluated once; it should yield an iterable\n",
      "object.  An iterator is created for the result of the\n",
      "\"expression_list\".  The suite is then executed once for each item\n",
      "provided by the iterator, in the order returned by the iterator.  Each\n",
      "item in turn is assigned to the target list using the standard rules\n",
      "for assignments (see Assignment statements), and then the suite is\n",
      "executed.  When the items are exhausted (which is immediately when the\n",
      "sequence is empty or an iterator raises a \"StopIteration\" exception),\n",
      "the suite in the \"else\" clause, if present, is executed, and the loop\n",
      "terminates.\n",
      "\n",
      "A \"break\" statement executed in the first suite terminates the loop\n",
      "without executing the \"else\" clause’s suite.  A \"continue\" statement\n",
      "executed in the first suite skips the rest of the suite and continues\n",
      "with the next item, or with the \"else\" clause if there is no next\n",
      "item.\n",
      "\n",
      "The for-loop makes assignments to the variables in the target list.\n",
      "This overwrites all previous assignments to those variables including\n",
      "those made in the suite of the for-loop:\n",
      "\n",
      "   for i in range(10):\n",
      "       print(i)\n",
      "       i = 5             # this will not affect the for-loop\n",
      "                         # because i will be overwritten with the next\n",
      "                         # index in the range\n",
      "\n",
      "Names in the target list are not deleted when the loop is finished,\n",
      "but if the sequence is empty, they will not have been assigned to at\n",
      "all by the loop.  Hint: the built-in type \"range()\" represents\n",
      "immutable arithmetic sequences of integers. For instance, iterating\n",
      "\"range(3)\" successively yields 0, 1, and then 2.\n",
      "\n",
      "Related help topics: break, continue, while\n",
      "\n",
      "\n",
      "You are now leaving help and returning to the Python interpreter.\n",
      "If you want to ask for help on a particular object directly from the\n",
      "interpreter, you can type \"help(object)\".  Executing \"help('string')\"\n",
      "has the same effect as typing a particular string at the help> prompt.\n"
     ]
    }
   ],
   "source": [
    "help()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ea79500-2490-4492-b909-1cb144b8fe72",
   "metadata": {},
   "source": [
    "# Python输出相关知识教程\n",
    "\n",
    "## 知识点1: print()函数\n",
    "\n",
    "### 1.1 print()函数的作用\n",
    "\n",
    "`print()`函数用于向控制台中输出数据，它可以输出任何类型的数据。\n",
    "\n",
    "### 1.2 print()函数的语法格式\n",
    "\n",
    "```\n",
    "pythonCopy code\n",
    "print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
    "```\n",
    "\n",
    "- `objects`（可选）: 要打印的对象，可以是一个或多个参数，用逗号分隔。如果有多个对象，它们将以空格为分隔符打印。\n",
    "- `sep`（可选）: 用于分隔多个对象之间的字符，默认为一个空格。\n",
    "- `end`（可选）: 输出结束时要追加的字符，默认为换行符 `\\n`。\n",
    "- `file`（可选）: 指定要写入的文件，默认为标准输出流（sys.stdout）。\n",
    "- `flush`（可选）: 是否立即将数据写入流，默认为 `False`。\n",
    "\n",
    "### 1.3 通过代码演示print()函数的基本使用\n",
    "\n",
    "```\n",
    "# 示例：使用print()函数输出字符串\n",
    "print(\"你好，世界！\")\n",
    "\n",
    "# 示例：使用print()函数输出多个参数，并自定义分隔符和结束符\n",
    "print(\"Python\", \"很\", \"厉害\", sep='-', end='!\\n')\n",
    "\n",
    "# 示例：使用print()函数输出表达式结果\n",
    "x = 10\n",
    "y = 20\n",
    "print(\"和:\", x + y)\n",
    "```\n",
    "\n",
    "## 知识点2: 转义字符\n",
    "\n",
    "### 2.1 转义字符的概念\n",
    "\n",
    "转义字符是由反斜杠 `\\` 与 ASCII 码组合而成，使组合后的字符产生新的含义。\n",
    "\n",
    "### 2.2 常用的转义字符\n",
    "\n",
    "- `\\b`: 退格\n",
    "- `\\n`: 换行符\n",
    "- `\\v`: 纵向制表符\n",
    "- `\\t`: 横向制表符\n",
    "- `\\r`: 回车符\n",
    "- `\\'`: 单引号字符\n",
    "- `\\\"`: 双引号字符\n",
    "\n",
    "### 2.3 通过代码演示转义字符的基本使用\n",
    "\n",
    "```\n",
    "# 示例：使用转义字符输出特殊格式的字符串\n",
    "print(\"你\\t好，世\\n界!\")\n",
    "\n",
    "# 示例：使用转义字符输出带引号的字符串\n",
    "print(\"她说: \\\"你好!\\\"\")\n",
    "\n",
    "# 示例：使用转义字符输出路径\n",
    "print(\"C:\\\\Users\\\\John\\\\Desktop\")\n",
    "\n",
    "# 示例：使用转义字符输出特殊字符\n",
    "print(\"嘟!\\a\")\n",
    "```\n",
    "\n",
    "以上就是关于`print()`函数和转义字符的详细介绍。希望本教程能帮助你更好地理解和使用这些常用的功能！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "359a6f81-e814-4eff-a138-e413d8ecd508",
   "metadata": {},
   "source": [
    "# Python输入函数教程\n",
    "\n",
    "在Python编程中，`input()`函数用于从用户获取输入。本教程将介绍如何使用`input()`函数来接收用户输入，并对输入进行处理。\n",
    "\n",
    "## 1. input()函数的基本用法\n",
    "\n",
    "`input()`函数接受一个字符串作为参数，用于提示用户输入内容，并等待用户输入完成，然后将用户输入的内容作为字符串返回。\n",
    "\n",
    "```\n",
    "# 示例：获取用户输入并输出\n",
    "name = input(\"请输入您的姓名: \")\n",
    "print(\"您好，\" + name + \"!\")\n",
    "```\n",
    "\n",
    "## 2. 用户输入的处理\n",
    "\n",
    "用户输入的内容默认为字符串类型，如果需要将其转换为其他类型，例如整数或浮点数，可以使用类型转换函数。\n",
    "\n",
    "### 2.1 将输入转换为整数\n",
    "\n",
    "```\n",
    "# 示例：获取用户输入并转换为整数\n",
    "age = input(\"请输入您的年龄: \")\n",
    "age = int(age)\n",
    "print(\"您的年龄是:\", age)\n",
    "```\n",
    "\n",
    "### 2.2 将输入转换为浮点数\n",
    "\n",
    "```\n",
    "# 示例：获取用户输入并转换为浮点数\n",
    "height = input(\"请输入您的身高（米）: \")\n",
    "height = float(height)\n",
    "print(\"您的身高是:\", height, \"米\")\n",
    "```\n",
    "\n",
    "## 3. 输入多个值\n",
    "\n",
    "可以使用`input()`函数多次获取用户输入，或者通过空格或其他分隔符来输入多个值，然后使用`split()`函数将其拆分为列表。\n",
    "\n",
    "```\n",
    "# 示例：输入多个值并进行处理\n",
    "numbers = input(\"请输入多个数字（用空格分隔）: \")\n",
    "numbers_list = numbers.split()  # 将输入的字符串以空格分割成列表\n",
    "print(\"您输入的数字列表为:\", numbers_list)\n",
    "```\n",
    "\n",
    "## 4. 注意事项\n",
    "\n",
    "- 用户输入的内容总是作为字符串处理，需要根据需要进行类型转换。\n",
    "- 使用`split()`函数时，要注意分隔符的选择，确保与用户输入的内容相匹配。\n",
    "\n",
    "通过本教程，您已经了解了如何使用`input()`函数来获取用户输入，并对输入进行处理。希望这能帮助您在Python编程中更灵活地与用户交互"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7733fcc0-b8a1-405e-9c33-b1828dfd4d4a",
   "metadata": {},
   "source": [
    "# Python变量教学\n",
    "\n",
    "## 什么是变量？\n",
    "\n",
    "在编程中，变量是用于存储数据的容器。你可以将变量视为标签，用来标识存储在计算机内存中的数据。\n",
    "\n",
    "## 变量的命名规则\n",
    "\n",
    "- 变量名可以包含字母、数字和下划线，但不能以数字开头。\n",
    "- 变量名不能包含空格，可以使用下划线来分隔单词。\n",
    "- 变量名是大小写敏感的，例如 `myVariable` 和 `myvariable\n",
    "- 建议常量名使用大写的单个单词或由下画线连接的多个单词；模块名、函数名使用小写的单个单词或由下画线连接的多个单词；类名使用大写字母开头的单个或多个单词` 是不同的变量名。\n",
    "\n",
    "## 声明变量\n",
    "\n",
    "在Python中，声明变量非常简单，只需使用\n",
    "号 `=` 进行赋值操作。\n",
    "\n",
    "```python\n",
    "my_variable = 10\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83225b30-8963-4922-b901-e17536af2f60",
   "metadata": {},
   "source": [
    "## 变量的类型\n",
    "\n",
    "Python中有不同类型的变量，例如整数、浮点数、字符串等。Python会自动推断变量的类型，无需显式声明。\n",
    "\n",
    "- 整数类型 (int)：整数类型用于表示没有小数部分的数字，可以是正数、负数或零。在Python中，整数类型使用 `int` 表示。\n",
    "- 浮点数类型 (float)：浮点数类型用于表示带有小数部分的数字，可以是正数、负数或零。在Python中，浮点数类型使用 `float` 表示。\n",
    "- 复数类型 (complex)：复数类型用于表示实部和虚部都是浮点数的数字。复数由实部和虚部构成，形式为 `a + bj`，其中 `a` 是实部，`b` 是虚部，而 `j` 是虚数单位。在Python中，复数类型使用 `complex` 表示。\n",
    "- 布尔类型 (bool)：布尔类型用于表示逻辑值，只有两个取值：`True` 和 `False`。在Python中，布尔类型使用 `bool` 表示。\n",
    "- 字符串类型 (str)：字符串类型用于表示文本数据，可以包含字母、数字、符号等字符。字符串要用引号（单引号或双引号）括起来。在Python中，字符串类型使用 `str` 表示。\n",
    "- 列表类型 (list)：列表类型用于存储一系列有序的元素，元素可以是不同的数据类型，列表可以动态修改。在Python中，列表类型使用 `list` 表示。\n",
    "- 元组类型 (tuple)：元组类型也用于存储一系列有序的元素，但元组是不可变的，即创建后不能修改。在Python中，元组类型使用 `tuple` 表示。\n",
    "- 集合类型 (set)：集合类型用于存储一组唯一的元素，集合中的元素是无序的，不重复的。在Python中，集合类型使用 `set` 表示。\n",
    "- 字典类型 (dict)：字典类型用于存储键值对（key-value pair）的数据，每个键值对之间用逗号分隔，键（key）必须是不可变的数据类型，如字符串、元组等，值（value）可以是任意数据类型。在Python中，字典类型使用 `dict` 表示。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5ea4320e-2306-4863-a67f-f0fd9d878b80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "<class 'int'>\n",
      "3.14\n",
      "<class 'float'>\n",
      "(2+3j)\n",
      "<class 'complex'>\n",
      "True\n",
      "<class 'bool'>\n",
      "Hello, World!\n",
      "<class 'str'>\n",
      "[1, 2, 3, 4, 5]\n",
      "<class 'list'>\n",
      "(1, 2, 3, 4, 5)\n",
      "<class 'tuple'>\n",
      "{1, 2, 3, 4, 5}\n",
      "<class 'set'>\n",
      "{'a': 1, 'b': 2, 'c': 3}\n",
      "<class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "# 整数类型 (int)\n",
    "my_integer = 10\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_integer)\n",
    "print(type(my_integer))\n",
    "\n",
    "# 浮点数类型 (float)\n",
    "my_float = 3.14\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_float)\n",
    "print(type(my_float))\n",
    "\n",
    "# 复数类型 (complex)\n",
    "my_complex = 2 + 3j\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_complex)\n",
    "print(type(my_complex))\n",
    "\n",
    "# 布尔类型 (bool)\n",
    "my_bool = True\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_bool)\n",
    "print(type(my_bool))\n",
    "\n",
    "# 字符串类型 (str)\n",
    "my_string = \"Hello, World!\"\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_string)\n",
    "print(type(my_string))\n",
    "\n",
    "# 列表类型 (list)\n",
    "my_list = [1, 2, 3, 4, 5]\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_list)\n",
    "print(type(my_list))\n",
    "\n",
    "# 元组类型 (tuple)\n",
    "my_tuple = (1, 2, 3, 4, 5)\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_tuple)\n",
    "print(type(my_tuple))\n",
    "\n",
    "# 集合类型 (set)\n",
    "my_set = {1, 2, 3, 4, 5}\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_set)\n",
    "print(type(my_set))\n",
    "\n",
    "# 字典类型 (dict)\n",
    "my_dict = {'a': 1, 'b': 2, 'c': 3}\n",
    "\n",
    "# 输出变量及其类型\n",
    "print(my_dict)\n",
    "print(type(my_dict))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c972d4d-b9e2-40ca-bf41-70844898fdb1",
   "metadata": {},
   "source": [
    "# Python基本数据类型操作教程\n",
    "\n",
    "## 1. 普通整数（int）操作\n",
    "\n",
    "在Python中，普通整数是没有小数部分的数字，可以进行基本的算术运算和位运算。\n",
    "\n",
    "```\n",
    "# 定义整数变量\n",
    "x = 5\n",
    "y = 3\n",
    "\n",
    "# 加法\n",
    "result = x + y\n",
    "print(\"加法结果:\", result)  # 输出: 8\n",
    "\n",
    "# 减法\n",
    "result = x - y\n",
    "print(\"减法结果:\", result)  # 输出: 2\n",
    "\n",
    "# 乘法\n",
    "result = x * y\n",
    "print(\"乘法结果:\", result)  # 输出: 15\n",
    "\n",
    "# 整数除法\n",
    "result = x / y\n",
    "print(\"除法结果:\", result)  # 输出: 1.6666666666666667\n",
    "\n",
    "# 整数取余\n",
    "result = x % y\n",
    "print(\"取余结果:\", result)  # 输出: 2\n",
    "\n",
    "# 整数幂运算\n",
    "result = x ** y\n",
    "print(\"幂运算结果:\", result)  # 输出: 125\n",
    "\n",
    "# 整数取整除\n",
    "result = x // y\n",
    "print(\"取整除结果:\", result)  # 输出: 1\n",
    "```\n",
    "\n",
    "## 2. 浮点数（float）操作\n",
    "\n",
    "浮点数是带有小数部分的数字，在Python中可以进行各种数学运算。\n",
    "\n",
    "```\n",
    "# 定义浮点数变量\n",
    "a = 3.5\n",
    "b = 2.0\n",
    "\n",
    "# 加法\n",
    "result = a + b\n",
    "print(\"加法结果:\", result)  # 输出: 5.5\n",
    "\n",
    "# 减法\n",
    "result = a - b\n",
    "print(\"减法结果:\", result)  # 输出: 1.5\n",
    "\n",
    "# 乘法\n",
    "result = a * b\n",
    "print(\"乘法结果:\", result)  # 输出: 7.0\n",
    "\n",
    "# 除法\n",
    "result = a / b\n",
    "print(\"除法结果:\", result)  # 输出: 1.75\n",
    "```\n",
    "\n",
    "## 3. 字符串（str）操作\n",
    "\n",
    "字符串是一系列字符的集合，在Python中可以进行多种操作，包括连接、切片、查找等。\n",
    "\n",
    "```\n",
    "# 定义字符串变量\n",
    "s1 = \"Hello\"\n",
    "s2 = \"World\"\n",
    "\n",
    "# 字符串连接\n",
    "result = s1 + \" \" + s2\n",
    "print(\"连接结果:\", result)  # 输出: Hello World\n",
    "\n",
    "# 字符串切片\n",
    "substring = s1[1:4]\n",
    "print(\"切片结果:\", substring)  # 输出: ell\n",
    "\n",
    "# 字符串长度\n",
    "length = len(s2)\n",
    "print(\"字符串长度:\", length)  # 输出: 5\n",
    "\n",
    "# 查找子串\n",
    "index = s2.find(\"or\")\n",
    "print(\"子串索引:\", index)  # 输出: 1\n",
    "```\n",
    "\n",
    "## 4. 布尔型（bool）操作\n",
    "\n",
    "布尔型只有两个取值，True和False，常用于逻辑判断。\n",
    "\n",
    "```\n",
    "# 定义布尔变量\n",
    "is_valid = True\n",
    "is_finished = False\n",
    "\n",
    "# 逻辑与\n",
    "result = is_valid and is_finished\n",
    "print(\"逻辑与结果:\", result)  # 输出: False\n",
    "\n",
    "# 逻辑或\n",
    "result = is_valid or is_finished\n",
    "print(\"逻辑或结果:\", result)  # 输出: True\n",
    "\n",
    "# 逻辑非\n",
    "result = not is_valid\n",
    "print(\"逻辑非结果:\", result)  # 输出: False\n",
    "```\n",
    "\n",
    "以上就是Python中普通整数、浮点数、字符串和布尔型的具体操作教程。这些基本数据类型是Python编程中的基石，熟练掌握它们的操作将有助于你更高效地编写Python程序。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "285e32bd-96c1-49b1-8152-aa506afe2650",
   "metadata": {},
   "source": [
    "# Python复数操作教程\n",
    "\n",
    "在Python中，复数是由实部和虚部组成的数学对象，表示为 `a + bi`，其中 `a` 是实部，`b` 是虚部，而 `i` 是虚数单位。本教程将介绍如何在Python中进行复数的基本操作，包括创建复数、复数运算等。\n",
    "\n",
    "## 1. 创建复数\n",
    "\n",
    "可以使用内置函数 `complex()` 来创建复数对象。复数可以由一个实部和一个虚部组成，也可以只指定实部或虚部。\n",
    "\n",
    "```\n",
    "# 创建一个复数\n",
    "z1 = complex(2, 3)  # 实部为2，虚部为3\n",
    "print(\"复数1:\", z1)  # 输出: (2+3j)\n",
    "\n",
    "# 只指定实部，虚部默认为0\n",
    "z2 = complex(4)\n",
    "print(\"复数2:\", z2)  # 输出: (4+0j)\n",
    "\n",
    "# 只指定虚部，实部默认为0\n",
    "z3 = complex(0, 5)\n",
    "print(\"复数3:\", z3)  # 输出: 5j\n",
    "```\n",
    "\n",
    "## 2. 复数属性和操作\n",
    "\n",
    "复数对象有一些属性和可以执行的操作，如获取实部、虚部、共轭等。\n",
    "\n",
    "### 2.1. 获取实部和虚部\n",
    "\n",
    "可以使用 `real` 和 `imag` 属性来获取复数的实部和虚部。\n",
    "\n",
    "```\n",
    "z = complex(2, 3)\n",
    "print(\"实部:\", z.real)  # 输出: 2.0\n",
    "print(\"虚部:\", z.imag)  # 输出: 3.0\n",
    "```\n",
    "\n",
    "### 2.2. 获取共轭复数\n",
    "\n",
    "可以使用 `conjugate()` 方法来获取复数的共轭复数。\n",
    "\n",
    "```\n",
    "z = complex(2, 3)\n",
    "conjugate_z = z.conjugate()\n",
    "print(\"共轭复数:\", conjugate_z)  # 输出: (2-3j)\n",
    "```\n",
    "\n",
    "## 3. 复数运算\n",
    "\n",
    "可以对复数进行加减乘除等数学运算，这些运算遵循复数的数学定义。\n",
    "\n",
    "```\n",
    "z1 = complex(2, 3)\n",
    "z2 = complex(1, 4)\n",
    "\n",
    "# 加法\n",
    "addition = z1 + z2\n",
    "print(\"加法结果:\", addition)  # 输出: (3+7j)\n",
    "\n",
    "# 减法\n",
    "subtraction = z1 - z2\n",
    "print(\"减法结果:\", subtraction)  # 输出: (1-1j)\n",
    "\n",
    "# 乘法\n",
    "multiplication = z1 * z2\n",
    "print(\"乘法结果:\", multiplication)  # 输出: (-10+11j)\n",
    "\n",
    "# 除法\n",
    "division = z1 / z2\n",
    "print(\"除法结果:\", division)  # 输出: (0.8-0.4j)\n",
    "```\n",
    "\n",
    "以上就是Python中复数的基本操作教程。复数是一种重要的数学概念，在某些情况下特别有用，比如在电路分析、信号处理等领域。希望本教程能帮助你更好地理解和使用复数！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f078b685-765e-489c-a385-bb3092fca154",
   "metadata": {},
   "source": [
    "## Python列表操作教程\n",
    "\n",
    "在Python编程中，列表（List）是一种非常常用的数据结构，它可以容纳任意数量的元素，并且支持各种操作，例如添加、删除、修改、遍历等。本教程将介绍Python中列表的基本操作，帮助你更好地理解和利用这一数据结构。\n",
    "\n",
    "### 1. 创建列表\n",
    "\n",
    "在Python中，可以使用方括号 `[]` 来创建一个列表。列表中的元素可以是任意类型的数据，包括整数、浮点数、字符串等。\n",
    "\n",
    "```\n",
    "# 创建一个空列表\n",
    "my_list = []\n",
    "\n",
    "# 创建一个包含整数的列表\n",
    "numbers = [1, 2, 3, 4, 5]\n",
    "\n",
    "# 创建一个包含字符串的列表\n",
    "fruits = ['apple', 'banana', 'orange']\n",
    "\n",
    "# 创建一个混合类型的列表\n",
    "mixed = [1, 'hello', 3.14, True]\n",
    "```\n",
    "\n",
    "### 2. 访问列表元素\n",
    "\n",
    "可以使用索引来访问列表中的元素，索引从0开始，表示第一个元素。\n",
    "\n",
    "```\n",
    "# 访问列表中的元素\n",
    "print(numbers[0])  # 输出: 1\n",
    "print(fruits[1])   # 输出: banana\n",
    "```\n",
    "\n",
    "也可以使用负索引来从列表末尾开始访问元素。\n",
    "\n",
    "```\n",
    "# 使用负索引访问列表元素\n",
    "print(numbers[-1])  # 输出: 5，最后一个元素\n",
    "print(fruits[-2])   # 输出: banana，倒数第二个元素\n",
    "```\n",
    "\n",
    "### 3. 列表切片\n",
    "\n",
    "除了单个元素，还可以使用切片来获取列表的子集。\n",
    "\n",
    "```\n",
    "# 切片操作\n",
    "print(numbers[1:4])  # 输出: [2, 3, 4]\n",
    "print(fruits[:2])    # 输出: ['apple', 'banana']，从头开始到索引为2的元素之前（不包括2）\n",
    "print(mixed[2:])     # 输出: [3.14, True]，从索引为2的元素开始到列表末尾\n",
    "```\n",
    "\n",
    "### 4. 修改列表元素\n",
    "\n",
    "列表是可变的数据类型，可以通过索引直接修改列表中的元素。\n",
    "\n",
    "```\n",
    "# 修改列表元素\n",
    "fruits[0] = 'pear'\n",
    "print(fruits)  # 输出: ['pear', 'banana', 'orange']\n",
    "```\n",
    "\n",
    "### 5. 添加和删除元素\n",
    "\n",
    "可以使用 `append()` 方法向列表末尾添加新元素，使用 `insert()` 方法在指定位置插入新元素。\n",
    "\n",
    "```\n",
    "# 添加元素\n",
    "fruits.append('grape')\n",
    "print(fruits)  # 输出: ['pear', 'banana', 'orange', 'grape']\n",
    "\n",
    "# 在指定位置插入元素\n",
    "fruits.insert(1, 'kiwi')\n",
    "print(fruits)  # 输出: ['pear', 'kiwi', 'banana', 'orange', 'grape']\n",
    "```\n",
    "\n",
    "要删除列表中的元素，可以使用 `remove()` 方法删除指定值的元素，使用 `pop()` 方法删除指定索引的元素。\n",
    "\n",
    "```\n",
    "# 删除元素\n",
    "fruits.remove('banana')\n",
    "print(fruits)  # 输出: ['pear', 'kiwi', 'orange', 'grape']\n",
    "\n",
    "# 删除指定索引的元素\n",
    "removed_item = fruits.pop(1)\n",
    "print(fruits)       # 输出: ['pear', 'orange', 'grape']\n",
    "print(removed_item) # 输出: kiwi\n",
    "```\n",
    "\n",
    "### 6. 列表操作方法\n",
    "\n",
    "除了上述常用的操作外，Python还提供了许多其他方法来操作列表，例如排序、反转、计数等。你可以查阅Python官方文档或其他教程来了解更多列表操作方法。\n",
    "\n",
    "```\n",
    "# 列表操作方法示例\n",
    "numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]\n",
    "\n",
    "# 添加元素\n",
    "numbers.append(7)\n",
    "print(numbers)  # 输出: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 7]\n",
    "\n",
    "# 插入元素\n",
    "numbers.insert(2, 8)\n",
    "print(numbers)  # 输出: [3, 1, 8, 4, 1, 5, 9, 2, 6, 5, 3, 7]\n",
    "\n",
    "# 删除元素\n",
    "numbers.remove(1)\n",
    "print(numbers)  # 输出: [3, 8, 4, 1, 5, 9, 2, 6, 5, 3, 7]\n",
    "\n",
    "# 删除指定索引的元素\n",
    "deleted = numbers.pop(3)\n",
    "print(numbers)  # 输出: [3, 8, 4, 5, 9, 2, 6, 5, 3, 7]\n",
    "print(deleted)  # 输出: 1\n",
    "\n",
    "# 返回指定值的索引\n",
    "index = numbers.index(5)\n",
    "print(index)    # 输出: 3\n",
    "\n",
    "# 返回指定值的出现次数\n",
    "count = numbers.count(5)\n",
    "print(count)    # 输出: 2\n",
    "\n",
    "# 对列表进行排序\n",
    "numbers.sort()\n",
    "print(numbers)  # 输出: [2, 3, 3, 4, 5, 5, 6, 7, 8, 9]\n",
    "\n",
    "# 反转列表\n",
    "numbers.reverse()\n",
    "print(numbers)  # 输出: [9, 8, 7, 6, 5, 5, 4, 3, 3, 2]\n",
    "\n",
    "# 返回列表的浅拷贝\n",
    "numbers_copy = numbers.copy()\n",
    "print(numbers_copy)  # 输出: [9, 8, 7, 6, 5, 5, 4, 3, 3, 2]\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a9c44c9-2450-4575-84ba-f83e10a40b55",
   "metadata": {},
   "source": [
    "# Python元组基本操作教程\n",
    "\n",
    "在Python编程中，元组（Tuple）是一种有序的、不可变的数据结构，可以容纳任意数量的元素，通常用圆括号 `()` 来表示。本教程将介绍Python中元组的基本操作，帮助你更好地理解和利用这一数据结构。\n",
    "\n",
    "## 1. 创建元组\n",
    "\n",
    "可以使用圆括号 `()` 来创建一个元组。元组中的元素可以是任意类型的数据，包括整数、浮点数、字符串等。\n",
    "\n",
    "```\n",
    "# 创建一个空元组\n",
    "empty_tuple = ()\n",
    "\n",
    "# 创建一个包含整数的元组\n",
    "numbers_tuple = (1, 2, 3, 4, 5)\n",
    "\n",
    "# 创建一个包含字符串的元组\n",
    "fruits_tuple = ('apple', 'banana', 'orange')\n",
    "\n",
    "# 创建一个混合类型的元组\n",
    "mixed_tuple = (1, 'hello', 3.14, True)\n",
    "```\n",
    "\n",
    "## 2. 访问元组元素\n",
    "\n",
    "可以使用索引来访问元组中的元素，索引从0开始，表示第一个元素。\n",
    "\n",
    "```\n",
    "# 访问元组中的元素\n",
    "print(numbers_tuple[0])  # 输出: 1\n",
    "print(fruits_tuple[1])   # 输出: banana\n",
    "```\n",
    "\n",
    "也可以使用负索引来从元组末尾开始访问元素。\n",
    "\n",
    "```\n",
    "# 使用负索引访问元组元素\n",
    "print(numbers_tuple[-1])  # 输出: 5，最后一个元素\n",
    "print(fruits_tuple[-2])   # 输出: banana，倒数第二个元素\n",
    "```\n",
    "\n",
    "## 3. 元组切片\n",
    "\n",
    "除了单个元素，还可以使用切片来获取元组的子集。\n",
    "\n",
    "```\n",
    "# 切片操作\n",
    "print(numbers_tuple[1:4])  # 输出: (2, 3, 4)\n",
    "print(fruits_tuple[:2])    # 输出: ('apple', 'banana')，从头开始到索引为2的元素之前（不包括2）\n",
    "print(mixed_tuple[2:])     # 输出: (3.14, True)，从索引为2的元素开始到元组末尾\n",
    "```\n",
    "\n",
    "## 4. 元组不可变性\n",
    "\n",
    "元组是不可变的数据类型，一旦创建就不能修改其元素。试图对元组进行修改会导致异常。\n",
    "\n",
    "```\n",
    "# 尝试修改元组元素（会导致异常）\n",
    "fruits_tuple[0] = 'pear'  # TypeError: 'tuple' object does not support item assignment\n",
    "```\n",
    "\n",
    "## 5. 元组操作方法\n",
    "\n",
    "由于元组是不可变的，因此没有像列表那样的方法来修改元组。但是可以使用一些内置函数来操作元组，如 `len()` 获取元组长度，`count()` 统计指定值在元组中出现的次数，`index()` 获取指定值的索引位置等。\n",
    "\n",
    "```\n",
    "# 元组操作方法示例\n",
    "numbers_tuple = (1, 2, 3, 4, 5)\n",
    "\n",
    "# 获取元组长度\n",
    "length = len(numbers_tuple)\n",
    "print(\"元组长度:\", length)  # 输出: 5\n",
    "\n",
    "# 统计指定值出现次数\n",
    "count = numbers_tuple.count(3)\n",
    "print(\"元素3出现次数:\", count)  # 输出: 1\n",
    "\n",
    "# 获取指定值的索引位置\n",
    "index = numbers_tuple.index(4)\n",
    "print(\"元素4的索引位置:\", index)  # 输出: 3\n",
    "```\n",
    "\n",
    "## 6. 元组解包\n",
    "\n",
    "元组解包是一种将元组中的元素分配给多个变量的方法。可以通过简单的赋值语句来实现。\n",
    "\n",
    "```\n",
    "# 元组解包示例\n",
    "fruits_tuple = ('apple', 'banana', 'orange')\n",
    "a, b, c = fruits_tuple\n",
    "print(\"解包结果:\", a, b, c)  # 输出: apple banana orange\n",
    "```\n",
    "\n",
    "以上就是Python元组的基本操作教程。元组是一种轻量级的数据结构，在某些情况下比列表更适合，特别是当需要创建不可变的数据集合时。希望本教程对你有所帮助！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95b6f3fc-140f-46a3-af2e-b0ba5a77b338",
   "metadata": {},
   "source": [
    "# Python集合基本操作教程\n",
    "\n",
    "在Python编程中，集合（Set）是一种无序、不重复的数据集合，可以进行各种集合运算，如交集、并集、差集等。本教程将介绍Python中集合的基本操作，帮助你更好地理解和利用这一数据结构。\n",
    "\n",
    "## 1. 创建集合\n",
    "\n",
    "可以使用大括号 `{}` 或者 `set()` 函数来创建一个集合。集合中的元素是唯一的，重复的元素会被自动去重。\n",
    "\n",
    "```\n",
    "# 使用大括号创建集合\n",
    "my_set = {1, 2, 3, 4, 5}\n",
    "\n",
    "# 使用set()函数创建集合\n",
    "another_set = set([3, 4, 5, 6, 7])\n",
    "\n",
    "# 创建空集合\n",
    "empty_set = set()\n",
    "```\n",
    "\n",
    "## 2. 访问集合元素\n",
    "\n",
    "由于集合是无序的，因此不能通过索引来访问集合中的元素。但是可以使用循环或者 `in` 关键字来检查集合中是否包含某个元素。\n",
    "\n",
    "```\n",
    "pythonCopy code# 使用循环访问集合元素\n",
    "for element in my_set:\n",
    "    print(element)\n",
    "\n",
    "# 检查集合中是否包含某个元素\n",
    "if 3 in my_set:\n",
    "    print(\"集合中包含元素 3\")\n",
    "```\n",
    "\n",
    "## 3. 集合操作\n",
    "\n",
    "### 3.1. 并集\n",
    "\n",
    "并集操作将两个集合中的所有元素合并成一个新的集合。\n",
    "\n",
    "```\n",
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "\n",
    "union_set = set1 | set2  # 使用 | 符号进行并集操作\n",
    "print(\"并集结果:\", union_set)  # 输出: {1, 2, 3, 4, 5}\n",
    "```\n",
    "\n",
    "### 3.2. 交集\n",
    "\n",
    "交集操作返回两个集合中都包含的元素。\n",
    "\n",
    "```\n",
    "intersection_set = set1 & set2  # 使用 & 符号进行交集操作\n",
    "print(\"交集结果:\", intersection_set)  # 输出: {3}\n",
    "```\n",
    "\n",
    "### 3.3. 差集\n",
    "\n",
    "差集操作返回在第一个集合中但不在第二个集合中的元素。\n",
    "\n",
    "```\n",
    "difference_set = set1 - set2  # 使用 - 符号进行差集操作\n",
    "print(\"差集结果:\", difference_set)  # 输出: {1, 2}\n",
    "```\n",
    "\n",
    "### 3.4. 对称差集\n",
    "\n",
    "对称差集操作返回在两个集合中但不同时出现的元素。\n",
    "\n",
    "```\n",
    "symmetric_difference_set = set1 ^ set2  # 使用 ^ 符号进行对称差集操作\n",
    "print(\"对称差集结果:\", symmetric_difference_set)  # 输出: {1, 2, 4, 5}\n",
    "```\n",
    "\n",
    "## 4. 集合方法\n",
    "\n",
    "Python提供了一些内置方法来操作集合，如添加元素、删除元素等。\n",
    "\n",
    "### 4.1. 添加元素\n",
    "\n",
    "可以使用 `add()` 方法向集合中添加新元素。\n",
    "\n",
    "```\n",
    "my_set.add(6)\n",
    "print(\"添加元素后的集合:\", my_set)  # 输出: {1, 2, 3, 4, 5, 6}\n",
    "```\n",
    "\n",
    "### 4.2. 删除元素\n",
    "\n",
    "可以使用 `remove()` 方法删除集合中的指定元素。\n",
    "\n",
    "```\n",
    "my_set.remove(2)\n",
    "print(\"删除元素后的集合:\", my_set)  # 输出: {1, 3, 4, 5, 6}\n",
    "```\n",
    "\n",
    "### 4.3. 清空集合\n",
    "\n",
    "可以使用 `clear()` 方法清空集合中的所有元素。\n",
    "\n",
    "```\n",
    "my_set.clear()\n",
    "print(\"清空集合后的集合:\", my_set)  # 输出: set()\n",
    "```\n",
    "\n",
    "以上就是Python集合的基本操作教程。集合是一种非常有用的数据结构，特别适合于去重和集合运算。希望本教程对你有所帮助！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ab227e3-4f6a-4271-8a0b-96d3e055a8d0",
   "metadata": {},
   "source": [
    "# Python字典基本操作教程\n",
    "\n",
    "在Python编程中，字典（Dictionary）是一种无序的、可变的数据结构，用于存储键值对。字典中的元素是唯一的，键（Key）必须是不可变的数据类型，如整数、字符串等，而值（Value）可以是任意类型的数据。本教程将介绍Python中字典的基本操作，帮助你更好地理解和利用这一数据结构。\n",
    "\n",
    "## 1. 创建字典\n",
    "\n",
    "可以使用大括号 `{}` 或者 `dict()` 函数来创建一个字典。每个键值对之间用冒号 `:` 分隔，键和值之间用逗号 `,` 分隔。\n",
    "\n",
    "```\n",
    "# 使用大括号创建字典\n",
    "my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York'}\n",
    "\n",
    "# 使用dict()函数创建字典\n",
    "another_dict = dict(name='Bob', age=25, city='Los Angeles')\n",
    "\n",
    "# 创建空字典\n",
    "empty_dict = {}\n",
    "```\n",
    "\n",
    "## 2. 访问字典元素\n",
    "\n",
    "可以使用键来访问字典中的元素。\n",
    "\n",
    "```\n",
    "# 访问字典中的元素\n",
    "print(my_dict['name'])  # 输出: Alice\n",
    "print(another_dict['age'])  # 输出: 25\n",
    "```\n",
    "\n",
    "如果访问一个不存在的键，会导致 KeyError 异常。\n",
    "\n",
    "```\n",
    "# 访问不存在的键（会导致异常）\n",
    "# print(my_dict['gender'])  # KeyError: 'gender'\n",
    "```\n",
    "\n",
    "为了避免 KeyError 异常，可以使用 `get()` 方法来访问字典中的元素，如果键不存在，则返回 None 或者指定的默认值。\n",
    "\n",
    "```\n",
    "# 使用get()方法访问字典中的元素\n",
    "print(my_dict.get('gender'))  # 输出: None\n",
    "print(my_dict.get('gender', 'Unknown'))  # 输出: Unknown\n",
    "```\n",
    "\n",
    "## 3. 修改字典元素\n",
    "\n",
    "可以通过赋值语句来修改字典中的元素。\n",
    "\n",
    "```\n",
    "# 修改字典中的元素\n",
    "my_dict['age'] = 35\n",
    "print(\"修改后的字典:\", my_dict)  # 输出: {'name': 'Alice', 'age': 35, 'city': 'New York'}\n",
    "```\n",
    "\n",
    "## 4. 添加和删除元素\n",
    "\n",
    "### 4.1. 添加元素\n",
    "\n",
    "可以使用赋值语句来向字典中添加新的键值对。\n",
    "\n",
    "```\n",
    "# 添加元素\n",
    "my_dict['gender'] = 'Female'\n",
    "print(\"添加元素后的字典:\", my_dict)  # 输出: {'name': 'Alice', 'age': 35, 'city': 'New York', 'gender': 'Female'}\n",
    "```\n",
    "\n",
    "### 4.2. 删除元素\n",
    "\n",
    "可以使用 `del` 关键字或者 `pop()` 方法来删除字典中的键值对。\n",
    "\n",
    "```\n",
    "# 删除元素\n",
    "del my_dict['city']\n",
    "print(\"删除元素后的字典:\", my_dict)  # 输出: {'name': 'Alice', 'age': 35, 'gender': 'Female'}\n",
    "\n",
    "# 使用pop()方法删除指定键的元素\n",
    "removed_value = my_dict.pop('age')\n",
    "print(\"被删除的元素值:\", removed_value)  # 输出: 35\n",
    "print(\"删除元素后的字典:\", my_dict)  # 输出: {'name': 'Alice', 'gender': 'Female'}\n",
    "```\n",
    "\n",
    "## 5. 字典方法\n",
    "\n",
    "Python提供了一些内置方法来操作字典，如获取所有键、获取所有值、获取所有键值对等。\n",
    "\n",
    "### 5.1. 获取所有键\n",
    "\n",
    "可以使用 `keys()` 方法获取字典中所有键的集合。\n",
    "\n",
    "```\n",
    "# 获取所有键\n",
    "keys = my_dict.keys()\n",
    "print(\"所有键:\", keys)  # 输出: dict_keys(['name', 'gender'])\n",
    "```\n",
    "\n",
    "### 5.2. 获取所有值\n",
    "\n",
    "可以使用 `values()` 方法获取字典中所有值的集合。\n",
    "\n",
    "```\n",
    "# 获取所有值\n",
    "values = my_dict.values()\n",
    "print(\"所有值:\", values)  # 输出: dict_values(['Alice', 'Female'])\n",
    "```\n",
    "\n",
    "### 5.3. 获取所有键值对\n",
    "\n",
    "可以使用 `items()` 方法获取字典中所有键值对的集合，每个键值对表示为一个元组。\n",
    "\n",
    "```\n",
    "# 获取所有键值对\n",
    "items = my_dict.items()\n",
    "print(\"所有键值对:\", items)  # 输出: dict_items([('name', 'Alice'), ('gender', 'Female')])\n",
    "```\n",
    "\n",
    "以上就是Python字典的基本操作教程。字典是一种非常灵活的数据结构，可以用来存储各种类型的数据，并且支持多种操作，如访问、修改、添加、删除等。希望本教程对你有所帮助！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6c031be-c28d-495e-bcb0-d67e8222ee11",
   "metadata": {},
   "source": [
    "# Python类型检查和类型转换\n",
    "\n",
    "## 知识点1: type()函数\n",
    "\n",
    "### 1.1 type()函数的作用\n",
    "\n",
    "Python解释器会根据变量保存的数据自动确定数据类型。通过`type()`函数可以查看变量的数据类型。\n",
    "\n",
    "### 1.2 type()函数的语法格式\n",
    "\n",
    "```\n",
    "type(object)\n",
    "```\n",
    "\n",
    "- `object`: 要获取其类型的对象。\n",
    "\n",
    "### 1.3 通过代码演示type()函数的使用\n",
    "\n",
    "```\n",
    "# 示例：使用type()函数检查变量的类型\n",
    "x = 5\n",
    "print(type(x))  # 输出: <class 'int'>\n",
    "\n",
    "y = 3.14\n",
    "print(type(y))  # 输出: <class 'float'>\n",
    "\n",
    "z = \"Hello\"\n",
    "print(type(z))  # 输出: <class 'str'>\n",
    "```\n",
    "\n",
    "## 知识点2: 类型转换函数\n",
    "\n",
    "### 2.1 数字类型的转换函数\n",
    "\n",
    "- `int()`: 将一个数或字符串转换为整数。\n",
    "- `float()`: 将一个数或字符串转换为浮点数。\n",
    "- `complex()`: 将一个数或字符串转换为复数。\n",
    "\n",
    "### 2.2 组合数据类型的转换函数\n",
    "\n",
    "- `str()`: 将对象转换为字符串。\n",
    "- `list()`: 将序列或可迭代对象转换为列表。\n",
    "- `tuple()`: 将序列或可迭代对象转换为元组。\n",
    "- `set()`: 将序列或可迭代对象转换为集合。\n",
    "\n",
    "### 2.3 通过代码演示类型转换函数的使用\n",
    "\n",
    "```\n",
    "# 示例：数字类型的转换函数\n",
    "a = int(3.14)\n",
    "print(a)  # 输出: 3\n",
    "\n",
    "b = float(\"5.6\")\n",
    "print(b)  # 输出: 5.6\n",
    "\n",
    "c = complex(2)\n",
    "print(c)  # 输出: (2+0j)\n",
    "\n",
    "# 示例：组合数据类型的转换函数\n",
    "s = str(123)\n",
    "print(s)  # 输出: '123'\n",
    "\n",
    "lst = list((1, 2, 3))\n",
    "print(lst)  # 输出: [1, 2, 3]\n",
    "\n",
    "t = tuple([4, 5, 6])\n",
    "print(t)  # 输出: (4, 5, 6)\n",
    "\n",
    "st = set([1, 2, 3])\n",
    "print(st)  # 输出: {1, 2, 3}\n",
    "```\n",
    "\n",
    "以上就是关于type()函数和类型转换函数的教程。希望通过本教程能够更好地理解Python中数据类型的检查和转换！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1803415-02f7-4c83-966c-4700248ec19d",
   "metadata": {},
   "source": [
    "# Python运算符教程\n",
    "\n",
    "运算符是用于执行各种操作的符号或特殊关键字。Python支持多种类型的运算符，包括算术运算符、逻辑运算符、赋值运算符、比较运算符、成员运算符等。本教程将介绍Python中常用的运算符以及它们的优先级。\n",
    "\n",
    "## 1. 算术运算符\n",
    "\n",
    "算术运算符用于执行基本的数学运算。\n",
    "\n",
    "| 运算符 | 描述           |\n",
    "| ------ | -------------- |\n",
    "| +      | 加             |\n",
    "| -      | 减             |\n",
    "| *      | 乘             |\n",
    "| /      | 除             |\n",
    "| %      | 取模（取余数） |\n",
    "| **     | 幂             |\n",
    "| //     | 整除（取整除） |\n",
    "\n",
    "## 2. 逻辑运算符\n",
    "\n",
    "逻辑运算符用于组合两个或多个条件。\n",
    "\n",
    "| 运算符 | 描述                               |\n",
    "| ------ | ---------------------------------- |\n",
    "| and    | 与，所有条件都为True时结果才为True |\n",
    "| or     | 或，任何条件为True时结果就为True   |\n",
    "| not    | 非，用于反转条件的结果             |\n",
    "\n",
    "## 3. 赋值运算符\n",
    "\n",
    "赋值运算符用于将值赋给变量。\n",
    "\n",
    "| 运算符 | 描述                         |\n",
    "| ------ | ---------------------------- |\n",
    "| =      | 将右边的值赋给左边的变量     |\n",
    "| +=     | 左右相加后赋值给左边的变量   |\n",
    "| -=     | 左右相减后赋值给左边的变量   |\n",
    "| *=     | 左右相乘后赋值给左边的变量   |\n",
    "| /=     | 左右相除后赋值给左边的变量   |\n",
    "| %=     | 左右取模后赋值给左边的变量   |\n",
    "| **=    | 左右幂运算后赋值给左边的变量 |\n",
    "| //=    | 左右整除后赋值给左边的变量   |\n",
    "\n",
    "## 4. 比较运算符\n",
    "\n",
    "比较运算符用于比较两个值。\n",
    "\n",
    "| 运算符 | 描述     |\n",
    "| ------ | -------- |\n",
    "| ==     | 等于     |\n",
    "| !=     | 不等于   |\n",
    "| >      | 大于     |\n",
    "| <      | 小于     |\n",
    "| >=     | 大于等于 |\n",
    "| <=     | 小于等于 |\n",
    "\n",
    "## 5. 成员运算符\n",
    "\n",
    "成员运算符用于测试序列中是否包含某个值。\n",
    "\n",
    "| 运算符 | 描述                                              |\n",
    "| ------ | ------------------------------------------------- |\n",
    "| in     | 如果在指定的序列中找到值返回 True，否则返回 False |\n",
    "| not in | 如果在指定的序列中找到值返回 False，否则返回 True |\n",
    "\n",
    "## 6. 运算符的优先级\n",
    "\n",
    "Python运算符按照优先级顺序执行。以下是常见运算符的优先级，从高到低：\n",
    "\n",
    "1. ** 指数 (最高优先级)\n",
    "2. +x, -x, ~x (一元加、减、按位取反)\n",
    "3. *, /, %, // (乘、除、取模、整除)\n",
    "4. +, - (加、减)\n",
    "5. <<, >> (左移、右移)\n",
    "6. & (按位与)\n",
    "7. ^ (按位异或)\n",
    "8. | (按位或)\n",
    "9. ==, !=, >, >=, <, <=, is, is not, in, not in (比较运算符和成员运算符)\n",
    "10. not (逻辑非)\n",
    "11. and (逻辑与)\n",
    "12. or (逻辑或)\n",
    "\n",
    "## 总结\n",
    "\n",
    "本教程介绍了Python中常见的运算符，包括算术运算符、逻辑运算符、赋值运算符、比较运算符和成员运算符，并列出了它们的优先级顺序。掌握这些运算符将有助于你编写更有效率和清晰的代码！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a105163-c77d-4e9c-bcf8-b75c0b55d9c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
